package com.mgkj.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mgkj.common.jwt.JwtHelper;
import com.mgkj.common.result.Result;
import com.mgkj.common.utils.MD5;
import com.mgkj.dto.UserLoginDto;
import com.mgkj.entity.CMSMV;
import com.mgkj.entity.Dscma;
import com.mgkj.entity.Employee;
import com.mgkj.mapper.CMSMVMapper;
import com.mgkj.mapper.DscmaMapper;
import com.mgkj.vo.CMSMVVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : ssy
 * @date: 2024-01-09
 * @Description:
 */
@RestController
@Api(tags = "登录接口")
@RequestMapping("/api/user")
public class UserController {

    @Autowired
    private DscmaMapper dscmaMapper;

    @ApiOperation("员工登入接口")
    @PostMapping("/dscma")
    public Result selectlogin(@RequestBody UserLoginDto userLoginDto) {
        // 根据账号查询员工
        String password=dscmaMapper.selectpassword(userLoginDto);
        if (password==null){
            return Result.fail("密码错误！").message("密码错误！");
        }else if (password.equals(userLoginDto.getPassword())){
            Dscma dscma = dscmaMapper.selectById(userLoginDto.getUserId());
            Map<String,Object> map = new HashMap<>();
            String token= JwtHelper.createToken(1L,userLoginDto.getUserId());
            map.put("token", token);
            map.put("DSCMA",dscma);

            return Result.ok(map).message("登录成功!");
        }else {
            return Result.fail("密码错误！").message("密码错误！");
        }
    }

}
